#include "configTask.h"
#include <stdio.h>
#include <string.h>
#include "FreertosCommon.h"
#include "BluetoothMsgParser.h"
#include "ConfigLogic.h"
extern QueueHandle_t configMsgQueueHandle;

void configMsgDispath(char* data);

void configTaskInit(){

	
}


void configTaskTaskFun(void * p){

	char * data;
	while (1) {
		
			// 从HC - 05消息队列接收数据  json字符串
			if (xQueueReceive(configMsgQueueHandle, &data, 0) == pdPASS) {
				 configMsgDispath(data);
			}
			vTaskDelay(2000);
	}

	
}

void configTaskCreate(){

	//创建一个启动任务
		BaseType_t result = xTaskCreate(
			configTaskTaskFun,
			CONFIG_TASK_NAME,
			CONFIG_TASK_STACK_DEPTH,
			NULL,
			CONFIG_TASK_PRIORITY,
			NULL
		);
	
	
	if(result==pdPASS)
		printf("create configTask task sucess!\r\n");
	else
	  printf("create configTask task fail!\r\n");
	
}


void configMsgDispath(char* data){
   
	//解析消息类型
	int msgType = parseMsgType(data);
	switch(msgType)
	{
		//魔鬼数字
		case MSG_TYPE_CONFIG_TH:
			configTh(data); //配置阈值
			break;
		case MSG_TYPE_CONFIG_NETWORK:
			configNetwork(data); //配置网络
			break;
		default:
			break;
	
	}

}
	